<?php
class BigsLibrary_Controller_Pager
	{
		function findStart($limit)
		{
			if((!isset($_GET['page']))||($_GET['page']=="1"))
			{
				$start=0;
				$_GET['page']=1;
			}
			else
			{
				$start=($_GET['page']-1)*$limit;
			}
			return $start;
		}
		
		function findPages($count, $limit)
		{
			$pages=(($count%$limit)==0)?($count/$limit):floor($count/$limit)+1;
			return $pages;
		}
		
		function pageList($curpage, $pages)
		{
			$page_list="";
			if(($curpage!=1)&&($curpage))
			{
				$page_list .="<p><a href=\"?page=1\" title=\"First page\"><<</a></p>";
				$page_list .=" ";
			}
			
			if(($curpage-1)>0)
			{
				$page_list .="<p><a href=\"?page=".($curpage-1)."\" title=\"Prev\"><</a></p>";
				$page_list .=" ";
			}
			
			for($i=1; $i<=$pages; $i++)
			{
				if($i==$curpage)
				{
					$page_list .="<p class='current'><b>".$i."</b></p>";
				}
				else
				{
					$page_list .="<p><a href=\"?page=".$i."\" title=\"Page ".$i."\">".$i."</a></p>";
				}
				$page_list .=" ";
			}
			
			if(($curpage+1)<=$pages)
			{
				$page_list .="<p><a href=\"?page=".($curpage+1)."\" title=\"Next\">></a></p>";
				$page_list .=" ";
			}
			if(($curpage!=$pages)&&($pages!=0))
			{
				$page_list .="<p><a href=\"?page=".$pages."\" title=\"End page\">>></a></p>";
			}
			//$page_list .="</td>\n";
			return $page_list;
		}
		
		function nextPrev($curpage, $pages)
		{
			$next_prev = "";
			if(($curpage-1)<=0)
			{
				$next_prev .="Prev";				
			}
			else
			{
				$next_prev .="<p><a href=\"?page=".($curpage-1)."\" >Prev</a></p>";
			}
			$next_prev .=" | ";
			
			if(($curpage+1)>$pages)
			{
				$next_prev .="Next";
			}
			else
			{
				$next_prev .="<p><a href=\""."?page=".($curpage+1)."\" >Next</a></p>";
			}
			return $next_prev;
		}
	}
    ?>